package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;

public class ComputerFrame extends JFrame{
	private static final long serialVersionUID = 4174621914605686809L;

	JMenuBar menuBar;
	JMenu choiceGrade;
	JMenuItem grade1;
	JMenuItem grade2;
	JTextField textOne;
	JTextField textTwo;
	JTextField textResult;
	JButton getProblem;
	JButton giveAnswer;
	JLabel operatorLabel;
	JLabel message;
	Teacher teacherZhang;
	
	public ComputerFrame() {
		teacherZhang = new Teacher();
		teacherZhang.setMaxInteger(20);
		setLayout(new FlowLayout());
		menuBar = new JMenuBar();
		choiceGrade = new JMenu("选择级别");
		grade1 = new JMenuItem("幼儿级别");
		grade2 = new JMenuItem("儿童级别");
		grade1.addActionListener((e) -> {
			teacherZhang.setMaxInteger(10);
		});
		grade2.addActionListener((e) -> {
			teacherZhang.setMaxInteger(50);
		});
		choiceGrade.add(grade1);
		choiceGrade.add(grade2);
		menuBar.add(choiceGrade);
		setJMenuBar(menuBar);
		textOne = new JTextField(5);
		textTwo = new JTextField(5);
		textResult = new JTextField(5);
		operatorLabel = new JLabel("+");
		operatorLabel.setFont(new Font("Arial", Font.BOLD, 20));
		message = new JLabel("你还没回答问题呢");
		getProblem = new JButton("获取题目");
		giveAnswer = new JButton("确认答案");
		add(textOne);
		add(operatorLabel);
		add(textTwo);
		add(new JLabel("="));
		add(textResult);
		add(giveAnswer);
		add(message);
		add(getProblem);
		textResult.requestFocus();
		textOne.setEditable(false);
		textTwo.setEditable(false);
		getProblem.setActionCommand("getProblem");
		textResult.setActionCommand("answer");
		giveAnswer.setActionCommand("answer");
		teacherZhang.setJTextField(textOne, textTwo, textResult);
		teacherZhang.setJLabel(operatorLabel, message);
		getProblem.addActionListener(teacherZhang);
		giveAnswer.addActionListener(teacherZhang);
		textResult.addActionListener(teacherZhang);
		setVisible(true);
		validate();
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	
}
